package com.iot.ammeter.common

import android.content.Context
import android.util.Log
import android.widget.Toast
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.Fragment
import com.iot.ammeter.R
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

const val noData = "--"

fun Context.onNetworkError(e: Exception) {
    Toast.makeText(this, "网络错误", Toast.LENGTH_SHORT).show()
    Log.d("Network Error", e.stackTraceToString())
}

/**
 * 将用余额和人民币单位拼接为字符串，金额保留两个小数
 * @see R.string.balance_unit
 */
fun Fragment.rmbString(balance: Float): String =
    "${getString(R.string.balance_unit)}${String.format("%.2f", balance)}"

/**
 * Composable 版本人民币字面量拼接函数
 */
@Composable
@ReadOnlyComposable
fun rmbString(balance: Float): String =
    "${stringResource(id = R.string.balance_unit)}${String.format("%.2f", balance)}"
